// scripts/organize-dist.mjs (注意文件扩展名改为.mjs)
import fs from 'fs-extra';
import path from 'path';
import { fileURLToPath } from 'url';

// 获取当前模块的路径
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function organize() {
  const distPath = path.join(__dirname, '../dist');
  
  // 确保types目录存在
  await fs.ensureDir(path.join(distPath, 'types'));

  // 组件列表
  try {
    // 处理类型文件（假设类型文件生成在dist/types临时目录）
    if (await fs.pathExists(path.join(distPath, 'types/src/packages'))) {
      await fs.move(
        path.join(distPath, 'types/src/packages'),
        path.join(distPath, 'types'),
        { overwrite: true }
      );
    }

    // 清理临时目录
    await fs.remove(path.join(distPath, 'types/src'));
    
    console.log('Dist directory organized successfully!');
  } catch (error) {
    console.error('Error organizing dist directory:', error);
    process.exit(1);
  }
}

// 执行组织函数
organize();